package com.zl.controller;

import com.zl.model.Classes;
import com.zl.service.ClassesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

@Controller
@RequestMapping("/classes")
public class ClassesController {

    @Autowired
    @Qualifier("ClassesServiceImpl")
    private ClassesServiceImpl classesService;

    /**
     * 查询全部
     * @param model
     * @return
     */
    @RequestMapping("/findAll")
    public String findAll2(Model model){
        List<Classes> list=classesService.findAll();
        model.addAttribute("list",list);
        return "main1";
    }

    /**
     * 查一个
     * @param model
     * @param class_id
     * @return
     */
    @RequestMapping("/findOne")
    public String findone(Model model,int class_id){
        Classes u=classesService.findOne(class_id);
        model.addAttribute("u",u);
        return "cupdate";
    }

    /**
     * 添加
     * @return
     */
    //1.去添加

    @RequestMapping("/toinsert")
    public String toinsert(){
        return "cadd";
    }
    //2.添加

    @RequestMapping("/insert")
    public String insert(Classes classes){
        classesService.insert(classes);
        return "redirect:/classes/findAll";
    }

    /**
     * 修改
     * @param classes
     * @return
     */
    @RequestMapping("/update")
    public String update(Classes classes){
        classesService.update(classes);
        return "redirect:/classes/findAll";
    }

    //返回主页面
    @RequestMapping("/tomain")
    public String tomain(){
        return "main";
    }
}
